<{include file="tpl/admin/header.html"}>
<script src="tpl/admin/src/js/jscal2.js"></script>
<script src="tpl/admin/src/js/unicode-letter.js"></script>
<script src="tpl/admin/src/js/lang/cn.js"></script>
<script type="text/javascript" src="tpl/js/jquery.boxy.js?ver=20091101"></script>
<link rel="stylesheet" type="text/css" href="tpl/admin/css/boxy.css?ver=20091102" />

<link rel="stylesheet" type="text/css" href="tpl/admin/src/css/jscal2.css" />
<link rel="stylesheet" type="text/css" href="tpl/admin/src/css/border-radius.css" />
<link rel="stylesheet" type="text/css" href="tpl/admin/src/css/steel/steel.css" />
    
<script type="text/javascript">
$(document).ready(function(){ // 当页面加载完毕的时候
	// 例子三
	$("#ex3button").click(function(){ // "提交"按钮被点击
		// 构造发送的数据，请注意如果获取表单各项的值
		var formdata = {
			'rulename' : $('#rulename').val(),
			'rulefile' : $('#rulefile').val(),
			'geturl' : $('#geturl').val(),
			'getlist' : $('#getlist').val(),
			'getlink' : $('#getlink').val(),
			'autocj' : $('#autocj').is(':checked')? "1":"0",
			'compatible' : $('#compatible').is(':checked')? "1":"0",
			'gethost' : $('#gethost').val(),
			'gettitle' : $('#gettitle').val(),
			'patterns' : $('#patterns').val(),
			'replacements' : $('#replacements').val(),
			'universal' : $('#universal').is(':checked')? "1":"0",
			'getdetailurl' : $('#getdetailurl').val(),
			'getrange' : $('#getrange').val(),
			'dpatterns' : $('#dpatterns').val(),
			'dreplacements' : $('#dreplacements').val(),
			'part' : $('#part').val(),
            'addtime' : $('#addtime').val(),
			'id' : $('#id').val()
		};
	
		var id  = $('#id').val();  // 根据有没有id 判断是编辑还是增加
		if(id == '')
		{
			// 用$.post发送数据
			$.post('<{spUrl c=rulesform a=adddata}>', formdata, function(result){
				$('#resulttable').append(result); // 返回的数据直接追加到resulttable表格的后面
				feedback(result,id);
			});
		}
		else
		{
		   	// 用$.post发送数据
			$.post('<{spUrl c=rulesform a=editdata}>', formdata, function(result){
				$('#resulttable').append(result); // 返回的数据直接追加到resulttable表格的后面
				feedback(result,id);
			});	
		}
		
	});
});

function del(id){
		$.get('<{spUrl c=rulesform a=deldata}>', 'id='+id, function(result){
			$('#ex1result').html(result); // 返回的数据直接显示在id=ex1result的span中。
			if(result == 1)
			{alert('删除成功!!');}else{alert('删除失败!!')}
			window.location.reload(); 
		});
}


function initialize(id){
		$.get('<{spUrl c=rulesform a=initialize}>', 'id='+id, function(result){
			$('#ex1result').html(result); // 返回的数据直接显示在id=ex1result的span中。
			if(result == 1)
			{alert('失效状态!!');}else{alert('设置失败!!')}
			window.location.reload(); 
		});
}

function approval(id){
		$.get('<{spUrl c=rulesform a=approval}>', 'id='+id, function(result){
			$('#ex1result').html(result); // 返回的数据直接显示在id=ex1result的span中。
			if(result == 1)
			{alert('使用状态!!');}else{alert('设置失败!!')}
			window.location.reload(); 
		});
}
</script> 

<script type="text/javascript">

// 搜索功能调用
function searchs(){
	var filter = $('#filter').val();
	if(filter != ''){
	  window.location.href="index.php?c=rulesform&a=index&t=info&limit=<{$limit}>&filter="+filter+"";
	}
}

// 分页设置
function Limit(nums){
	var filter = $('#filter').val();
	if(nums.value == '')
	{window.location.href="index.php?c=rulesform&a=index&t=info&limit=<{$limit}>&filter="+filter+"";}
	else
	{window.location.href="index.php?c=rulesform&a=index&t=info&limit="+nums.value+"&filter="+filter+"";}
}

// 搜索快捷键
<!--  
function hotkey()  
{  
	var a=window.event.keyCode;  
	if((a==13))  
	{  
	   	var filter = $('#filter').val();
		if(filter != ''){
		window.location.href="index.php?c=rulesform&a=index&t=info&limit=<{$limit}>&filter="+filter+"";
		}
	}  
	}// end hotkey  
	document.onkeydown = hotkey; //当onkeydown 事件发生时调用hotkey函数  
//-->  
 </script>
 
<script type="text/javascript" charset="utf-8">
	/*ajax 调数据 留用代码 误删 ******/
/*   $(document).ready(function() {
		$('#example').dataTable( {
			"bProcessing": true,
			"bServerSide": true,
			"sAjaxSource": "scripts/server_processing.php"
		} );
	} );*/
</script>
        
<div class="breadcrumbs">
	<div class="container-fluid">
		<ul class="bread pull-left">
			<li>
				<a href="index.php?c=manage&a=index"><i class="icon-home icon-white"></i></a>
			</li>
			<li>
				<a href="index.php?c=rulesform&a=index&t=info&limit=<{$limit}>">
					采集规则表
				</a>
			</li>
		</ul>

	</div>
</div>
<div class="main">
    <{include file="tpl/admin/left.html"}>
	<div class="container-fluid">
		<div class="content">
			<div class="row-fluid">
				<div class="span12">
					<div class="box">
						<div class="box-head tabs">
							<h3>采集规则表 | <a href="index.php?c=rulesform&a=index&t=info&limit=<{$limit}>#mao">添加</a></h3>
							<ul class='nav nav-tabs'>
								<li class='active'>
									<a href="#basic" data-toggle="tab">Basic</a>
								</li>
								<li>
									<a href="#nohead" data-toggle="tab">No header</a>
								</li>
							</ul>
						</div>
						<div class="box-content box-nomargin">
							<div class="tab-content">
									<div class="tab-pane active" id="basic">
                                    <!--分页设置-->
                                    <div id="DataTables_Table_0_length" class="dataTables_length">
                                    <label>Limit: 
                                    <select id="Limit" size="1" onchange="Limit(this)" class="uniform">
                                    <option  <{if $limit eq '10'}>selected<{/if}> value="10">10</option>
                                    <option  <{if $limit eq '25'}>selected<{/if}> value="25">25</option>
                                    <option  <{if $limit eq '50'}>selected<{/if}> value="50">50</option>
                                    <option  <{if $limit eq '100'}>selected<{/if}> value="100">100</option>
                                    </select></label>
                                    </div>
                                    <!--搜索设置-->
                                    <div class="dataTables_filter" id="DataTables_Table_0_filter">
                                    <label><input id="filter" type="text" onblur="searchs()" placeholder="<{$filter}>"></label>
                                    </div>
										<table class='table table-striped dataTable table-condensed'>
												<tr>
                                                    <th>规则名称</th>
                                                    <th>来源</th>
                                                    <th>地址</th>
                                                    <th>分类</th>
                                                    <th>添加时间</th>
                                                    <th>操作</th>
												</tr>
                                              <{foreach item=colorname from=$result key=enname}>
                                              <tr>
                                                 <td><{$colorname.rulename}></td>
                                                 <td><{$colorname.rulefile}></td>
                                                 <td><a target="_blank" href="<{$colorname.geturl}>">点击查看</a>
                                                 </td>
                                                 <td><{$colorname.part}></td>
                                                 <td><{$colorname.addtime|date_format:"%Y-%m-%d:%H:%M:%S"}></td>
                                                 <td>
                                                 <{if $colorname.approval eq '0'}>
                                                 <a href="javascript:approval(<{$colorname.id}>)">失效状态</a> | 
                                                 <a href="index.php?c=rulesform&a=index&t=info&id=<{$colorname.id}>&limit=<{$limit}>#mao">编辑</a> | 
                                                 <a href="javascript:del(<{$colorname.id}>);">删除</a>
                                             <{else}>
                                              <a href="javascript:initialize(<{$colorname.id}>);">正常使用</a> |
                                              <a href="index.php?c=rulesform&a=index&t=info&id=<{$colorname.id}>&limit=<{$limit}>#mao">编辑</a> | 
                                                 <a href="javascript:del(<{$colorname.id}>);">删除</a>
                                              <{/if}></td>
                                              </tr>
                                              <{/foreach}>
										</table>
									</div>
									<div class="tab-pane" id="nohead">
										<table class='table table-striped dataTable dataTable-noheader table-bordered'>
											<thead>
												<tr>
                                                    <th>规则名称</th>
                                                    <th>来源</th>
                                                    <th>分类</th>
                                                    <th>添加时间</th>
                                                    <th>操作</th>
												</tr>
											</thead>
											<tbody>
                                              <{foreach item=colorname from=$result key=enname}>
                                              <tr>
                                                 <td><{$colorname.rulename}></td>
                                                 <td><{$colorname.rulefile}></td>
                                                 <td><{$colorname.part}></td>
                                                 <td><{$colorname.addtime|date_format:"%Y-%m-%d:%H:%M:%S"}></td>
                                                 <td>
                                                  <{if $colorname.approval eq '0'}>
                                                     <a href="javascript:approval(<{$colorname.id}>)">通过</a> | <a href="javascript:refuse(<{$colorname.id}>);">拒绝</a> | <a href="index.php?c=rulesform&a=index&t=info&id=<{$colorname.id}>&limit=<{$limit}>#mao">编辑</a> | <a href="javascript:del(<{$colorname.id}>);">删除</a>
                                             <{else}>
                                             已经表态
                                              <a href="javascript:initialize(<{$colorname.id}>);">初始化</a>
                                              <{/if}>
                                                 </td>
                                              </tr>
                                              <{/foreach}>
											</tbody>
										</table>
									</div>
                                    <!--分页栏目-->
                                    <div class="dataTables_info" id="DataTables_Table_0_info">
                                    <{if $pager}>
                                    共有信息<{$pager.total_count}>条，共有<{$pager.total_page}>页（每页<{$pager.page_size}>条信息）：
                                    <{/if}>
                                    </div>
                                    <div class="dataTables_paginate paging_bootstrap pagination">
                                           <ul>
                                             <{if $pager}>
                                            <!--在当前页不是第一页的时候，显示前页和上一页-->
                                            <{if $pager.current_page != $pager.first_page}>
                                            <li><a href="index.php?c=rulesform&a=index&t=info&page=<{$pager.first_page}>&limit=<{$limit}>&filter=<{$filter}>">前页</a> </li>
                                            <!--<li><a href="index.php?c=rulesform&a=index&t=info&page=<{$pager.prev_page}>">上一页</a></li> -->
                                            <{/if}>
                                            <li><a href="index.php?c=rulesform&a=index&t=info&page=<{$pager.prev_page}>&limit=<{$limit}>&filter=<{$filter}>">上一页</a></li> 
                                            <!--开始循环页码，同时如果循环到当前页则不显示链接-->
                                            <{foreach from=$pager.all_pages item=thepage}>
                                                    <{if $thepage != $pager.current_page}>
                                                            <!--<a href="<{spUrl c=rulesform a=index a=index page=$thepage}>"><{$thepage}></a>-->
                                                           <li><a href="index.php?c=rulesform&a=index&t=info&page=<{$thepage}>&limit=<{$limit}>&filter=<{$filter}>"><{$thepage}></a></li>
                                                    <{else}>
                                                           <li class="active"><a><{$thepage}></a></li>
                                                    <{/if}>
                                            <{/foreach}>
                                            <!--在当前页不是最后一页的时候，显示下一页和后页-->
                                            <li><a href="index.php?c=rulesform&a=index&t=info&page=<{$pager.next_page}>&limit=<{$limit}>&filter=<{$filter}>">下一页</a></li>
                                            <{if $pager.current_page != $pager.last_page}>
                                            <li><a href="index.php?c=rulesform&a=index&t=info&page=<{$pager.last_page}>&limit=<{$limit}>&filter=<{$filter}>">后页</a></li>
                                            <{/if}>
                                            <{/if}>
                                           </ul>
                                   </div>
                                   <!--分页栏目-->
						</div>
					</div>
				</div>
			</div>
            <div class="row-fluid">
				<div class="span12">
					<div class="box">
						<div class="box-head">
						<a href="" name="mao"></a>
                           <{if $id != 0}>
                              <h3>编辑数据</h3>
                           <{else}>
                              <h3>增加数据</h3>
                           <{/if}>
						</div>
						<div class="box-content" >                            
							<form action="#" class='validate form-horizontal'>
								<div class="control-group">
									<label for="req" class="control-label">规则名称</label>
									<div class="controls">
                                     <input type="text" name="rulename" id="rulename" class='required' value="<{$rulename}>">
									<span></span>
                                    </div>
								</div>
                                <div class="control-group">
                                   <label for="req" class="control-label">来源：</label>
                                   <div class="controls">
                                   <input type="text" name="rulefile" id="rulefile" value="<{$rulefile}>">
                                   <span></span>
                                  </div>
                                </div>
                                
                           <div class="control-group">
                                  <label for="req" class="control-label">【兼容模式】：</label>
                                   <div class="controls">
                                   <{if $compatible == '1'}>
                                       <input id="compatible" name="compatible" type="checkbox" checked />
                                    <{else}>
                                       <input id="compatible" name="compatible" type="checkbox" />
                                    <{/if}>
                                   <span></span>
                                  </div>
                            </div>
                                
                               <div class="control-group">
                                   <label for="req" class="control-label">【获取源码】：</label>
                                   <div class="controls">
                                   <input id="geturl" name="geturl" size="60" type="text" value="<{$geturl}>">
                                   <input id="getcode" class='btn btn-primary' name="66" type="button" value="获取源码">
                                   <span></span>
                                   <hr style="width:400px;" />
                                  </div>
                                </div>
                                                               
                               <div class="control-group">
                                   <label for="req" class="control-label">【获取列表】：</label>
                                   <div class="controls">
                                   <input id="getlist" name="getlist" size="60" type="text" value='<{$getlist}>'>
                                   <input id="getlistcode" class='btn btn-primary' name="66" type="button" value="获取列表">
                                   <span></span>
                                   <hr style="width:400px;" />
                                  </div>
                                </div>
              
                              <div class="control-group">
                                  <label for="req" class="control-label">【获取链接】：</label>
                                   <div class="controls">
                                   <input id="getlink" name="getlink" size="60" type="text" value='<{$getlink}>'>
                                   <span></span>
                                  </div>
                                </div> 
                                
                                
                           <div class="control-group">
                                  <label for="req" class="control-label">【自动获取】：</label>
                                   <div class="controls">
                                   <{if $autocj == '1'}>
                                       <input id="autocj" name="autocj" type="checkbox" checked />
                                    <{else}>
                                       <input id="autocj" name="autocj" type="checkbox" />
                                    <{/if}>
                                   <span></span>
                                  </div>
                            </div>
                            
                            <div class="control-group">
                                  <label for="req" class="control-label">【获取链接】：</label>
                                   <div class="controls">
                                   <input id="gethost" name="gethost" size="60" type="text" value='<{$gethost}>'>
                                   <input id="getlinkcode" class='btn btn-primary' name="66" type="button" value="获取链接">
                                   <span></span>
                                   <hr style="width:400px;" />
                                  </div>
                            </div>

                              <div class="control-group">
                                  <label for="req" class="control-label">【标题规则】：</label>
                                   <div class="controls">
                                   <input id="gettitle" name="gettitle" size="60" type="text" value='<{$gettitle}>'>
                                   <span></span>
                                  </div>
                                </div>
                              <div class="control-group">
                                  <label for="req" class="control-label">【待替换目标】：</label>
                                   <div class="controls">
                                   <input id="patterns" name="patterns" size="60" type="text" value='<{$patterns}>'>
                                   <span></span>
                                  </div>
                                </div>
                              <div class="control-group">
                                  <label for="req" class="control-label">【替换后结果】：</label>
                                   <div class="controls">
                                   <input id="replacements" name="replacements" size="60" type="text" value='<{$replacements}>'>
                                   <input id="gettitlecode" class='btn btn-primary' name="66" type="button" value="获取标题">
                                   <span></span>
                                   <hr style="width:400px;" />
                                  </div>
                                </div>

                           <div class="control-group">
                                  <label for="req" class="control-label">【通用获取】：</label>
                                   <div class="controls">
                                    <{if $universal == '1'}>
                                       <input id="universal" name="universal" type="checkbox" checked />
                                    <{else}>
                                       <input id="universal" name="universal" type="checkbox" />
                                    <{/if}>
                                   <input id="getuniversalcode" class='btn btn-primary' name="66" type="button" value="通用方法获取标题和链接">
                                   <span></span>
                                  </div>
                            </div>
   
                          <hr style="width:400px;" />
                           <div class="control-group">
                                  <label for="req" class="control-label">【文章地址】：</label>
                                   <div class="controls">
                                  <input id="getdetailurl" name="getdetailurl" size="60" type="text" value="<{$getdetailurl}>">
                                   <span></span>
                                  </div>
                            </div>
                            
                          <div class="control-group">
                                  <label for="req" class="control-label">【匹配规则】：</label>
                                   <div class="controls">
                                   <input id="getrange" name="getrange" size="60" type="text" value='<{$getrange}>'>
                                   <span></span>
                                  </div>
                            </div>
                            
                           <div class="control-group">
                                  <label for="req" class="control-label">【待替换目标】：</label>
                                   <div class="controls">
                                   <input id="dpatterns" name="dpatterns" size="60" type="text" value='<{$dpatterns}>'>
                                   <span></span>
                                  </div>
                            </div>
                            
                                <div class="control-group">
                                  <label for="req" class="control-label">【替换后结果】：</label>
                                   <div class="controls">
                                   <input id="dreplacements" name="dreplacements" size="60" type="text" value='<{$dreplacements}>'>
                                   <input id="getdetailcode" class='btn btn-primary' name="66" type="button" value="获取内容">
                                   <span></span>
                                  </div>
                               </div>

                                <div class="control-group">
                                   <label for="req" class="control-label">分类：</label>
                                  <div class="controls">   
                                  <select name="part" id="part">
                                   <option selected value="0">根目录</option>
                                   <{foreach item=resultclassname from=$resultclass key=enname}>
                                     <{if $part == $resultclassname.id}>
                                        <option selected value="<{$resultclassname.id}>"><{$resultclassname.cname}></option>
                                     <{else}>
                                        <option value="<{$resultclassname.id}>"><{$resultclassname.cname}></option>
                                     <{/if}>
                                   <{/foreach}>
                                  </select>
                                  <span></span>
                                  </div>
                                </p>
                                </div>
                                <div class="control-group">
                                  <label for="req" class="control-label">添加时间：</label>
                                  <div class="controls">
                                  <input type="text" name="addtime" id="addtime" value="<{$addtime}>">
                                  <script type="text/javascript">//<![CDATA[
                                    Calendar.setup({
                                      inputField : "addtime",
                                      trigger    : "addtime",
                                      onSelect   : function() { this.hide() },
                                      showTime   : 24,
                                      dateFormat : "%Y-%m-%d %H:%M:%S"
                                    });
                                  //]]>
                                  </script>
                                  <span></span>
                                  </div>
                                </p>
                                </div>
								<div class="form-actions">
									<input type="button" id="ex3button" value="提交" class='btn btn-primary'>
                                    <input type="hidden" name="id" id="id" value="<{$id}>">
								</div>
							</form>
						</div>
					</div>
				</div>
		</div>	
	</div>
</div>	
<script src="Acquisition/artDialog4.1.6/artDialog.js?skin=default"></script>
<script src="Acquisition/artDialog4.1.6/plugins/iframeTools.js"></script>
<script>
$(document).ready(function(){  
  $('#getcode').click(function (){  
       var geturl = $('#geturl').val();
	   var compatible = $('#compatible').is(':checked')? "1":"0";
       showDialog(geturl,null,null,null,null,null,null,null,null,compatible,1);
  });  
  $('#getlistcode').click(function (){  
       var geturl = $('#geturl').val();
       var getlist = $('#getlist').val();
	   var compatible = $('#compatible').is(':checked')? "1":"0";
       showDialog(geturl,getlist,null,null,null,null,null,null,null,compatible,2);
  });  
  $('#getlinkcode').click(function (){  
       var geturl = $('#geturl').val();
       var getlist = $('#getlist').val();
	   var getlink = $('#getlink').val();
	   var gethost = $('#gethost').val();
	   var auto = $('#autocj').is(':checked')? "1":"0";
	   var compatible = $('#compatible').is(':checked')? "1":"0";
	   showDialog(geturl,getlist,getlink,auto,gethost,null,null,null,null,compatible,3);
  });  
  $('#gettitlecode').click(function (){  
       var geturl = $('#geturl').val();
       var getlist = $('#getlist').val();
	   var getlink = $('#getlink').val();
	   var gethost = $('#gethost').val();
	   var gettitle = $('#gettitle').val();
	   var patterns = $('#patterns').val();
	   var replacements = $('#replacements').val();
	   var compatible = $('#compatible').is(':checked')? "1":"0";
       showDialog(geturl,getlist,getlink,null,gethost,gettitle,patterns,replacements,null,compatible,4);
  }); 
  $('#getuniversalcode').click(function (){  
       var geturl = $('#geturl').val();
       var getlist = $('#getlist').val();
	   var gethost = $('#gethost').val();
	   var patterns = $('#patterns').val();
	   var replacements = $('#replacements').val();
	   var universal = $('#universal').is(':checked')? "1":"0";
	   var compatible = $('#compatible').is(':checked')? "1":"0";
       showDialog(geturl,getlist,getlink,null,gethost,gettitle,patterns,replacements,universal,compatible,5);
  }); 
  
  $('#getdetailcode').click(function (){  
       var getdetailurl = $('#getdetailurl').val();
	   var getrange = $('#getrange').val();
	   var dpatterns = $('#dpatterns').val();
	   var dreplacements = $('#dreplacements').val();
	   var compatible = $('#compatible').is(':checked')? "1":"0";
       DetailDialog(getdetailurl,getrange,dpatterns,dreplacements,compatible);
  }); 
});  

function showDialog(geturl,getlist,getlink,auto,gethost,gettitle,patterns,replacements,universal,compatible,mode){
	if(mode == 1)
	{
		art.dialog.open('Acquisition/getcode.php?geturl='+geturl+'&compatible='+compatible,
		{title: '获取源码', width: 980, height: 500});
	}
	
	if(mode == 2)
	{
		art.dialog.open('Acquisition/getlist.php?geturl='+geturl+'&getlist='+getlist+'&compatible='+compatible,
		{title: '获取列表', width: 980, height: 500});
	}
	
	if(mode == 3)
	{
		if(auto == 0)
		{
		   art.dialog.open('Acquisition/getlink.php?geturl='+geturl+'&getlist='+getlist+'&getlink='+getlink+'&auto='+auto+'&getlink='+getlink+'&gethost='+gethost+'&compatible='+compatible,
		   {title: '获取链接', width: 980, height: 500});
		}
		else
		{
		   art.dialog.open('Acquisition/getlink.php?geturl='+geturl+'&getlist='+getlist+'&getlink='+getlink+'&auto='+auto+'&getlink='+getlink+'&gethost='+gethost+'&compatible='+compatible,
		   {title: '获取链接(自动)', width: 980, height: 500});
		}
	}
	
	if(mode == 4)
	{
		art.dialog.open('Acquisition/gettitle.php?geturl='+geturl+'&getlist='+getlist+'&getlink='+getlink+'&gettitle='+gettitle+'&patterns='+patterns+'&replacements='+replacements+'&compatible='+compatible,
		{title: '获取标题', width: 980, height: 500});
	}
	
	if(mode == 5)
	{
		art.dialog.open('Acquisition/getuniversal.php?geturl='+geturl+'&getlist='+getlist+'&getlink='+getlink+'&gethost='+gethost+'&patterns='+patterns+'&replacements='+replacements+'&universal='+universal+'&compatible='+compatible,
		{title: '通用方法获取标题和链接', width: 980, height: 500});
	}
}

function DetailDialog(getdetailurl,getrange,dpatterns,dreplacements,compatible){
        art.dialog.open('Acquisition/getdetail.php?getdetailurl='+getdetailurl+'&getrange='+getrange+'&dpatterns='+dpatterns+'&dreplacements='+dreplacements+'&compatible='+compatible,
		{title: '获取内容', width: 980, height: 500});
}
</script>
<{include file="tpl/admin/footer.html"}>